Shell

推荐列表 站点导航

当前位置:首页 > 脚本编程 > Shell >

javascript修改表格背景色的示例代码

来源:互联网  作者:网友投稿  发布时间:2021-01-05 18:50
分享一例javascript实现的修改表格背景颜色的代码,有兴趣尝试下的朋友,可以参考学习下,对学习js脚本IT之家很有帮...

例子: 复制代码 代码示例: html script //点击当前选中行时设置当前行的颜色, 本节内容: javascript修改表格背景色的实例代码, /div table width=100% border=1 cellspacing=1 cellpadding=0 id=ServiceListTable tr th服务事项/th thN/th th状态/th th办结/th th资料/th /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr /table /body /html ,参考之前写的通过js给页面元素添加事件对应的表格,同时恢复除当前行外的行的颜色及鼠标事件 //by www.xuewangzhan.net function selectRow(target) { var sTable = document.getElementById(ServiceListTable) for(var i=1;isTable.rows.length;i++) //遍历除第一行外的所有行 { if (sTable.rows[i] != target) //判断是否当前选定行 { // sTable.rows[i].bgColor = #ffffff; //设置背景色 sTable.rows[i].onmouseover = resumeRowOver; //增加onmouseover 事件 sTable.rows[i].onmouseout = resumeRowOut;//增加onmouseout 事件 } else { sTable.rows[i].bgColor = #d3d3d3; sTable.rows[i].onmouseover = ; //去除鼠标事件 sTable.rows[i].onmouseout = ; //去除鼠标事件 } } } //移过时tr的背景色 function rowOver(target) { target.bgColor='#e4e4e4'; } //移出时tr的背景色 function rowOut(target) { target.bgColor='#ffffff'; } //恢复tr的的onmouseover事件配套调用函数 function resumeRowOver() { rowOver(this); } //恢复tr的的onmouseout事件配套调用函数 function resumeRowOut() { rowOut(this); } /script body div style=width:50px;height:50px;background-color:Blue onmouseover=javascript:this.style.backgroundColor='red'; onmouseout=javascript:this.style.backgroundColor='blue'关于最后两个函数resumeRowOver和resumeRowOut,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/shell/11216.shtml

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

javascript修改表格背景色的示例代码

2021-01-05 编辑:网友投稿

例子: 复制代码 代码示例: html script //点击当前选中行时设置当前行的颜色, 本节内容: javascript修改表格背景色的实例代码, /div table width=100% border=1 cellspacing=1 cellpadding=0 id=ServiceListTable tr th服务事项/th thN/th th状态/th th办结/th th资料/th /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr tr onmouseover=rowOver(this) onmouseout=rowOut(this) onclick=selectRow(this) td相关内容/td td align=center /td td align=center /td td align=center /td td align=center /td /tr /table /body /html ,参考之前写的通过js给页面元素添加事件对应的表格,同时恢复除当前行外的行的颜色及鼠标事件 //by www.xuewangzhan.net function selectRow(target) { var sTable = document.getElementById(ServiceListTable) for(var i=1;isTable.rows.length;i++) //遍历除第一行外的所有行 { if (sTable.rows[i] != target) //判断是否当前选定行 { // sTable.rows[i].bgColor = #ffffff; //设置背景色 sTable.rows[i].onmouseover = resumeRowOver; //增加onmouseover 事件 sTable.rows[i].onmouseout = resumeRowOut;//增加onmouseout 事件 } else { sTable.rows[i].bgColor = #d3d3d3; sTable.rows[i].onmouseover = ; //去除鼠标事件 sTable.rows[i].onmouseout = ; //去除鼠标事件 } } } //移过时tr的背景色 function rowOver(target) { target.bgColor='#e4e4e4'; } //移出时tr的背景色 function rowOut(target) { target.bgColor='#ffffff'; } //恢复tr的的onmouseover事件配套调用函数 function resumeRowOver() { rowOver(this); } //恢复tr的的onmouseout事件配套调用函数 function resumeRowOut() { rowOut(this); } /script body div style=width:50px;height:50px;background-color:Blue onmouseover=javascript:this.style.backgroundColor='red'; onmouseout=javascript:this.style.backgroundColor='blue'关于最后两个函数resumeRowOver和resumeRowOut,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/shell/11216.shtml

相关文章

风云图片

推荐阅读

返回Shell频道首页